% parameters
% Constant timestepping: grid S doubled for each run, timestep doubled.
% Variable timestepping: grid S doubled, timestep 4 times more,
% dnorm halved

rows = 5; % # times the program will be runned
T = 0.25; step0 = 25;
r = 0.03; sigma = 0.4; S0 = 100; K = 100; D = 1; option = 0;
nodeM = 1:rows; tol = 10^-6;
% Time Step
stepsVar = step0*4.^(0:rows-1);
stepsConst = step0*2.^(0:rows-1);
dnorm = 0.1./2.^(0:rows-1);
V = zeros(rows,1);
nNode = zeros(rows,1);
nsteps = zeros(rows,1);
tic
% Constant Timestepping
for i=1:rows
    [V(i), nsteps(i), optionV] = americanPen(r, sigma,S0,K,T,stepsConst(i),option, ...
        nodeM(i), D, dnorm(i), 0, tol);
    nNode(i) = length(optionV);
end
toc

change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputConst = [nNode,stepsConst',dnorm',V,change,ratio];
figure
% Variable Timestepping
for i=1:rows
    [V(i), nsteps(i), optionV] = americanPen(r, sigma,S0,K,T,stepsVar(i),option, ...
        nodeM(i), D, dnorm(i), 1, tol);
    nNode(i) = length(optionV);
end
toc
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputVar = [nNode,nsteps,dnorm',V,change,ratio];

